<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesResources;
use Fukuball\Jieba\Jieba;
use Fukuball\Jieba\Finalseg;
use Fukuball\Jieba\JiebaAnalyse;

class GetTagController extends BaseController
{
    use AuthorizesRequests, AuthorizesResources, DispatchesJobs;

    public function index()
    {
        return view('home')->with('articles', \App\Article::all());
      //  $file=$_SERVER['DOCUMENT_ROOT'].'/../json.txt';
      //  $content=file_get_contents($file);
      //  $datas=json_decode($content);
      //  $return =[];
      //  foreach ($datas as $data){
      //      $length=strlen($data[0]);
      //      if($length>2 && $length<20)
      //          $return[]=$data[0];
      //  }
      //  return array_values(array_unique($return));
    }

    public function store(Request $request)
    {
        $content = $request->input('content');
        if (strlen($content) > 0) {
            ini_set('memory_limit', '2000M');
            $time = time();
            Jieba::init(['mode']);
            Finalseg::init();
            JiebaAnalyse::init();
            Jieba::loadUserDict($_SERVER['DOCUMENT_ROOT'].'/../user_dict.txt');

//            $fcs = Jieba::cut($content);
            $tags=JiebaAnalyse::extractTags($content,10);
            $time2 = time();
            return ['tag'=>$tags, 'start' => $time, 'end' => $time2,'use'=>$time2-$time, 'code'=>200];
        } else {
            return '{code:0,msg:\'获取的信息为空\'}';
        }
    }

}
